class SendToUnity {
    private _channel: BroadcastChannel;

    constructor() {
        let randomKey = this.getRandomKey().toString();
        sessionStorage.setItem("channelKey", randomKey)
        this._channel = new BroadcastChannel(randomKey);
    }

    private getRandomKey() {
        return Math.random() * 100000;
    }

    public send(message: SendUnityData) {
        this._channel.postMessage(message);
    }
}

const Instance = new SendToUnity();
export default Instance;
